﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Unity;
using WPControla.Client.Services;
using WPControla.Client.ViewModels;
using WPControla.Client.Services.Rss;
using WPControla.Client.Services.Podcast;

namespace WPControla.Client.IoC
{
    /// <summary>
    /// DI container accesor
    /// </summary>
    public class Container : IContainer
    {
        static IUnityContainer _currentContainer;

        /// <summary>
        /// Get the current configured container
        /// </summary>
        /// <returns>Configured container</returns>
        public static IUnityContainer Current
        {
            get
            {
                return _currentContainer;
            }
        }

        static Container()
        {
            ConfigureContainer();
        }

        static void ConfigureContainer()
        {
            _currentContainer = new UnityContainer();

            //ViewModels
            _currentContainer.RegisterType<IVMMainPage, VMMainPage>();
            _currentContainer.RegisterType<IVMViewArticle, VMViewArticle>();
            _currentContainer.RegisterType<IVMViewChapter, VMViewChapter>();
            _currentContainer.RegisterType<IVMViewTweet, VMViewTweet>();

            //Services
            _currentContainer.RegisterType<INavigationService, NavigationService>();
            _currentContainer.RegisterType<IRssService, RssService>();
            _currentContainer.RegisterType<IPodcastService, PodcastService>();
            _currentContainer.RegisterType<IAudioService, AudioService>();

        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TService"></typeparam>
        /// <returns></returns>
        public TService Resolve<TService>()
        {
            return _currentContainer.Resolve<TService>();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public object Resolve(Type type)
        {
            return _currentContainer.Resolve(type, null);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"></param>
        public void RegisterType(Type type)
        {
            _currentContainer.RegisterType(type, new TransientLifetimeManager());
        }
    }
}
